package org.pine.manager;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import org.pine.manager.bo.UserBo;
import org.pine.manager.convertor.UserConvertor;
import org.pine.manager.query.UserQuery;
import org.pine.model.entity.User;
import org.pine.model.mapper.UserMapper;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * 用户管理类
 *
 * @author pine
 * @version v1.0
 * @since 2025-04-12 14:35
 */
@Component
@Transactional(rollbackFor = Exception.class)
public class UserManager extends BaseManager<UserMapper, User, UserBo, UserQuery, UserConvertor> {

    @Override
    protected LambdaQueryWrapper<User> encapsulateQueryWrapper(UserQuery query) {
        LambdaQueryWrapper<User> queryWrapper = super.encapsulateQueryWrapper(query);

        queryWrapper.eq(ObjectUtil.isNotEmpty(query.getLoginAccount()), User::getLoginAccount, query.getLoginAccount());
        queryWrapper.eq(ObjectUtil.isNotEmpty(query.getUsername()), User::getUsername, query.getUsername());
        queryWrapper.ge(ObjectUtils.isNotEmpty(query.getEnableTimeStart()), User::getEnableTime, query.getEnableTimeStart());
        queryWrapper.le(ObjectUtils.isNotEmpty(query.getEnableTimeEnd()), User::getEnableTime, query.getEnableTimeEnd());
        queryWrapper.ge(ObjectUtils.isNotEmpty(query.getDisableTimeStart()), User::getDisableTime, query.getDisableTimeStart());
        queryWrapper.le(ObjectUtils.isNotEmpty(query.getDisableTimeEnd()), User::getDisableTime, query.getDisableTimeEnd());
        queryWrapper.eq(ObjectUtil.isNotEmpty(query.getStatus()), User::getStatus, query.getStatus());
        queryWrapper.in(ObjectUtil.isNotEmpty(query.getStatusList()), User::getStatus, query.getStatusList());

        return queryWrapper;
    }
}
